﻿import VTitle from '@/components/common/MainTitle.vue'
export default {
  components: {
    VTitle
  },
  data () {
    return {
      titleName: '数据集管理',
      loading: false,
      // 跳转到新页面的信息
      dialogInfo: {
        operationType: '',
        rowInfo: null
      },
      // 表格
      tableData: [],
      tableColumn: [
        {
          text: '数据集名称',
          indexName: 'title'
        },
        {
          text: '数据源名称',
          indexName: 'source_name'
        },
        {
          text: '目标表名称',
          indexName: 'target'
        },
        {
          text: 'join表名称',
          indexName: 'joins'
        },
        {
          text: '是否测试成功',
          indexName: 'is_test_success'
        },
        {
          text: '是否启用',
          indexName: 'is_active'
        }
      ],
      // 页码部分
      totalLength: 0,
      // 获取表格数据的查询参数
      requestParams: {
        limit: 10,
        page: 1,
        filter: ''
      }
    }
  },
  created () {
    this.getAllData()
  },
  methods: {
    // 获取所有数据集列表
    getAllData () {
      this.loading = true
      this.$get('/icpdataset', {
        limit: this.requestParams.limit,
        page: this.requestParams.page,
        filter: this.requestParams.filter
      }).then((data) => {
        let dataResult = data.data.result
        if (dataResult.code === 'success') {
          this.tableData = dataResult.data.QueryDatas
          this.totalLength = dataResult.data.TotalRow
          this.requestParams.page = dataResult.data.CurrentPage
        } else {
          this.$message({
            message: dataResult.msg,
            type: 'warning'
          })
        }
        this.loading = false
      }).catch((error) => {
        this.$message({
          message: error,
          type: 'error'
        })
      })
    },
    // 查询时
    getSearchInfo () {
      this.requestParams.page = 1
      this.getAllData()
    },
    // 底部页码的部分
    handleSizeChange (val) {
      this.requestParams.limit = val
      this.getAllData()
    },
    handleCurrentChange (val) {
      this.requestParams.page = val
      this.getAllData()
    },
    // 新增时
    handleAdd () {
      this.dialogInfo.rowInfo = null
      this.dialogInfo.operationType = 'add'
      this.$router.push({
        path: '/dashboard/dataSetForm',
        query: {
          info: JSON.stringify(this.dialogInfo)
        }
      })
    },
    // 编辑时
    handleEdit (row) {
      this.dialogInfo.rowInfo = JSON.parse(JSON.stringify(row))
      this.dialogInfo.operationType = 'edit'
      this.$router.push({
        path: '/dashboard/dataSetForm',
        query: {
          info: JSON.stringify(this.dialogInfo)
        }
      })
    },
    // 查看详细时
    handleDetail (row) {
      this.dialogInfo.rowInfo = JSON.parse(JSON.stringify(row))
      this.dialogInfo.operationType = 'preview'
      this.$router.push({
        path: '/dashboard/dataSetForm',
        query: {
          info: JSON.stringify(this.dialogInfo)
        }
      })
    },
    // 删除
    handleDelete (row) {
      this.$confirm('此操作将永久删除该数据集信息, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        cancelButtonClass: 'el-button--info'
      }).then(() => {
        this.loading = true
        this.submitDelete(row)
      }).catch(() => {})
    },
    // 确定删除时
    submitDelete (row) {
      this.$delete('/icpdataset/' + row.uid).then(data => {
        if (data.status === 204) {
          this.$message({
            message: '删除成功',
            type: 'success'
          })
          this.getAllData()
        } else {
          this.$message({
            message: data.statusText,
            type: 'warning'
          })
          this.loading = false
        }
      }).catch(error => {
        console.log(error)
      })
    },
    // 启用的方法
    handleActive (row) {
      this.loading = true
      this.$patch('/icpdataset/' + row.uid + '/active').then(data => {
        let dataResult = data.data.result
        if (dataResult.code === 'success') {
          this.$message({
            message: '启用成功',
            type: 'success'
          })
          this.getAllData()
        } else {
          this.$message({
            message: dataResult.msg,
            type: 'warning'
          })
          this.loading = false
        }
      }).catch(error => {
        console.log(error)
      })
    },
    // 停用的方法
    handleDeactive (row) {
      this.loading = true
      this.$patch('/icpdataset/' + row.uid + '/deactive').then(data => {
        let dataResult = data.data.result
        if (dataResult.code === 'success') {
          this.$message({
            message: '停用成功',
            type: 'success'
          })
          this.getAllData()
        } else {
          this.$message({
            message: dataResult.msg,
            type: 'warning'
          })
          this.loading = false
        }
      }).catch(error => {
        console.log(error)
      })
    }
  }
}
